Imports Aricie.DNN.Caching.Analysis
Imports Aricie.DNN.UI.Controls
Imports Aricie.DNN.Settings
Imports DotNetNuke.Common
Imports DotNetNuke.UI.Skins.Controls
Imports DotNetNuke.Services.Exceptions
Imports DotNetNuke.Services.Localization
Imports DotNetNuke.UI.Skins
Imports Aricie.DNN.Security.Trial
Imports Aricie.Services
Imports DotNetNuke.UI.Utilities

Namespace Aricie.DNN.Caching.UI

    Partial Class DistributedCachingProviderConfig
        Inherits AriciePortalModuleBase

        Protected ReadOnly Property DistributedCachingSettings() As DistributedCachingProviderSettings
            Get
                Return DistributedCachingProviderBase.Settings
            End Get
        End Property

        Private Shared _WelcomeDisplayed As Boolean

#Region "Event Handlers"

        Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
            Me.EnforceFreeVersion()
            Me.BindSettings()
        End Sub

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
            Try
                ClientAPI.AddButtonConfirm(Me.cmdUninstall, Localization.GetString("ConfirmUninstall.Message", Me.LocalResourceFile))
                If Not Me.IsPostBack Then
                    If AssertInstalled() Then

                        If Not _WelcomeDisplayed Then
                            _WelcomeDisplayed = True
                            Skin.AddModuleMessage(Me, Localization.GetString("Welcome.Message", Me.LocalResourceFile), _
                                                   ModuleMessage.ModuleMessageType.GreenSuccess)
                        End If
                    End If
                End If



            Catch ex As Exception
                ProcessModuleLoadException(Me, ex)
            End Try
        End Sub




        'Config

       


        Protected Sub cmdInstall_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdInstall.Click
            Try
                Aricie.DNN.Configuration.ConfigHelper.ProcessModuleUpdate(Configuration.ConfigActionType.Install, New DistributedCachingConfigUpdate)
                Response.Redirect(NavigateURL())
            Catch ex As Exception
                ProcessModuleLoadException(Me, ex)
            End Try
        End Sub

        Protected Sub cmdUninstall_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdUninstall.Click
            Try
                Configuration.ConfigHelper.ProcessModuleUpdate(Configuration.ConfigActionType.Uninstall, New DistributedCachingConfigUpdate)
                Response.Redirect(Me.Request.Url.AbsoluteUri)
            Catch ex As Exception
                ProcessModuleLoadException(Me, ex)
            End Try
        End Sub

      


      
     

#End Region

#Region "Private methods"

        Private Sub EnforceFreeVersion()

            Dim tc As TrialController = TrialController.Instance(New TrialProvider())
            Dim objTrialStatus As TrialStatusInfo = tc.LimitModule(Me, True)
            Me.ctlSettings.TrialStatus = objTrialStatus
            'If objTrialStatus.Status = TrialStatus.Expired Then
            '    Me.cmdSave.Enabled = False
            'End If

        End Sub


        Private Sub BindSettings()
            Me.ctlSettings.LocalResourceFile = Me.SharedResourceFile
            Me.ctlSettings.DataSource = Me.DistributedCachingSettings
            Me.ctlSettings.DataBind()
        End Sub



        'Private Sub Reset()
        '    DistributedCachingBusinessController.SaveSettings(Me.GetDefaultSettings)
        '    Me.Response.Redirect(NavigateURL())
        'End Sub

        Private Function AssertInstalled() As Boolean
            Dim updater As New DistributedCachingConfigUpdate
            Aricie.DNN.Configuration.ConfigHelper.AssertIsInstalled(Me, updater, Me.cmdInstall, New Control() {Me.cmdUninstall, Me.divConfig})
            If Me.UserInfo.IsSuperUser Then
                Me.divInstall.Visible = True

            Else
                Me.divInstall.Visible = False
            End If
            Return Aricie.DNN.Configuration.ConfigHelper.IsInstalled(updater, True)
        End Function


        'Private Function GetDefaultSettings() As DistributedCachingProviderSettings
        '    Dim toReturn As New DistributedCachingProviderSettings
        '    toReturn.ClientSettings.AddDefaultProviders()
        '    toReturn.CloudSettings.StartupKeys.Add(toReturn.CloudSettings.CatalogKey)
        '    Return toReturn
        'End Function

#End Region


    End Class
End Namespace